var express = require('express');
var session = require('express-session');
var path = require('path');
var router = express.Router();
var sqlite3 = require('sqlite3').verbose();
/* GET users listing. */
router.post('/', function (req, res, next) {
  var username = req.body.username;
  var mode = req.body.mode;
  var db = new sqlite3.Database(path.join(__dirname, "../db/data.s3db"));
  if (mode == '2') {
    var img = req.body.url;
    var truename = req.body.truename;
    var phone = req.body.phone;
    try {
      db.run("UPDATE user SET truename ='" + truename + "', phone='" + phone + "',img='" + img + "' WHERE username='" + username + "'");
      res.send('1');
    } catch (ex) {
      console.log(ex);
    }
  } else if (mode == '3') {
    try {
      db.serialize(function () {
        sqlStr = "SELECT * from user where username=='" + username + "'";
        db.all(sqlStr, function (err, rows) {
          res.send(rows[0]);
        });
      });
    } catch (ex) {
      console.log(ex);
    }
  }
});

module.exports = router;